package com.softer.chengxin.excel.service.impl;

import com.softer.chengxin.common.domin.Common;
import com.softer.chengxin.excel.dao.ExcelStreetDao;
import com.softer.chengxin.excel.service.ExcelStreetService;
import com.softer.chengxin.home.domin.Street;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Gong Zhiyang
 * @date 2019/2/19
 */
@Service
public class ExcelStreetServiceImpl implements ExcelStreetService {

    @Autowired
    private ExcelStreetDao excelStreetDao;

    /**
     * 获取地区下拉列表
     *
     * @param id 登陆账号ID
     * @return 地区列表
     */
    @Override
    public List<Street> getExcelStreet(Integer id) {
        List<Street> result = new ArrayList<>();
        Street s=new Street();
        s.setId("0");
        s.setLabel("全部地区");
        result.add(s);
        List<Street> list = excelStreetDao.getExcelStreet(Common.ZERO, id);
        if (list != null) {
            for (Street street : list) {
                List<Street> children = excelStreetDao.getExcelStreet(street.getId(),id);
                street.setChildren(children);
            }
            result.addAll(list);
            return result;
        }
        return new ArrayList<>();
    }
}
